package Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

//集合间的操作
public class CollectionOperDemo {
    public static void main(String[] args) {
        Collection c1 = new ArrayList();
        c1.add("java");
        c1.add("c");
        c1.add("c++");
        c1.add("c#");
        System.out.println(c1);

        Collection c2 = new ArrayList();
        c2.add("html");
        c2.add("c++");
        c2.add("sql");
        System.out.println(c2);

        c1.addAll(c2);//并集
        System.out.println("c1"+c1);
        System.out.println("c2"+c2);

        Collection c3 = new ArrayList();
        c3.add("c++");
        c3.add("c#");
        c3.add("php");
        boolean coti = c1.containsAll(c3);
        System.out.println(coti);
        //交集
        c1.retainAll(c3);
        System.out.println(c1);

        c2.removeAll(c3);//差集
        System.out.println(c2);
        System.out.println(c3);

        //迭代器
        Iterator it = c1.iterator();
        while (it.hasNext()){
            String str = (String) it.next();
            System.out.println(str);
        }
    }
}
